#include <stdlib.h> 
#include <stdio.h> 
#include <SDL/SDL.h> 
#include <SDL/SDL_mixer.h> 
#include <SDL/SDL_image.h> 
#include <SDL/SDL_ttf.h> 


int main(int argc, char *argv[]) 
{ 
    SDL_Surface *ecran = NULL, *cheval = NULL,*chat =NULL,*poule=NULL,*chien=NULL,*tigre=NULL, *chevalclic = NULL,*chatclic =NULL,*pouleclic=NULL,*chienclic=NULL,*tigreclic=NULL,*fondpoule =NULL,*fondchat=NULL,*fondtigre=NULL,*fondcheval=NULL,*fondchien=NULL,*texte1 = NULL,*texte2 = NULL,*texte3 = NULL,*texte4 = NULL,*texte5 = NULL,*sound; 
    SDL_Rect positioncheval,positionchat,positionpoule,positionchien,positiontigre,positionfondpoule,positionfondtigre, positionfondchat,positionfondcheval,positionfondchien,position,positionsound; 
   
    TTF_Font *police = NULL; 
    Mix_Chunk *music1,*music2,*music3,*music4,*music5; 
    SDL_Color couleurNoire = {0, 0, 0}; 
    int continuer = 1,b=0,c=5,d=0; 
    SDL_Init(SDL_INIT_VIDEO); 
    SDL_WM_SetCaption("SDL_Mixer", NULL); 
    Mix_AllocateChannels(32); 
 Mix_Volume(1, MIX_MAX_VOLUME/2); 
    TTF_Init(); 

    positionfondpoule.x =0; 
    positionfondpoule.y =0; 
    positionfondchat.x =0; 
    positionfondchat.y = 0; 
    positionfondtigre.x =0; 
    positionfondtigre.y = 0; 
    positionfondcheval.x =0; 
    positionfondcheval.y = 0; 
    positionfondchien.x =0; 
    positionfondchien.y = 0; 


    positioncheval.x =700; 
    positioncheval.y = 60; 
    positionchat.x =700; 
    positionchat.y = 160; 
    positionchien.x = 700; 
    positionchien.y = 260; 
    positionpoule.x = 700; 
    positionpoule.y = 360; 
    positiontigre.x = 700; 
    positiontigre.y = 460; 

    position.x =  80; 
    position.y = 470; 
 
    positionsound.x =600; 
    positionsound.y =60; 
  
    SDL_Init(SDL_INIT_VIDEO); 
 
  SDL_WM_SetCaption("Chargement d'images en SDL", NULL); 
  fondpoule= SDL_LoadBMP("poule.bmp"); 
  SDL_WM_SetCaption("Chargement d'images en SDL", NULL); 
  fondchat = SDL_LoadBMP("chat.bmp"); 
  SDL_WM_SetCaption("Chargement d'images en SDL", NULL); 
  fondtigre = SDL_LoadBMP("tigre.bmp"); 
  SDL_WM_SetCaption("Chargement d'images en SDL", NULL); 
  fondcheval = SDL_LoadBMP("cheval.bmp"); 
  SDL_WM_SetCaption("Chargement d'images en SDL", NULL); 
  fondchien = SDL_LoadBMP("chien.bmp"); 
  
    SDL_WM_SetCaption("Gestion des événements en SDL", NULL); 

    cheval = SDL_LoadBMP("chevalbt.bmp"); 
    SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
    chat = SDL_LoadBMP("chatbt.bmp"); 
    SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
    poule = SDL_LoadBMP("poulebt.bmp"); 
    SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
    chien = SDL_LoadBMP("chienbt.bmp"); 
    SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
    tigre = SDL_LoadBMP("tigrebt.bmp"); 
    SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 

    chevalclic = SDL_LoadBMP("chevalbtClic.bmp"); 
    SDL_BlitSurface(chevalclic, NULL, ecran, &positioncheval); 
    chatclic = SDL_LoadBMP("chatbtClic.bmp"); 
    SDL_BlitSurface(chatclic, NULL, ecran, &positionchat); 
    pouleclic = SDL_LoadBMP("poulebtClic.bmp"); 
    SDL_BlitSurface(pouleclic, NULL, ecran, &positionpoule); 
    chienclic = SDL_LoadBMP("chienbtClic.bmp"); 
    SDL_BlitSurface(chienclic, NULL, ecran, &positionchien); 
    tigreclic = SDL_LoadBMP("tigrebtClic.bmp"); 
    SDL_BlitSurface(tigreclic, NULL, ecran, &positiontigre); 

    sound = SDL_LoadBMP("play_sound.bmp"); 
    SDL_BlitSurface(sound, NULL, ecran, &positionsound); 

    ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE |SDL_DOUBLEBUF); 
    SDL_Event event; 


   SDL_WM_SetCaption("SDL_Mixer", NULL); 
   SDL_Flip(ecran); 
   if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) //Initialisation de l'API Mixer 
   { 
      printf("%s", Mix_GetError()); 
   } 
   Mix_AllocateChannels(32); 

   
    SDL_WM_SetCaption("Gestion du texte avec SDL_ttf", NULL); 
    
    police = TTF_OpenFont("ComicPerso.ttf", 120); 

    texte1 = TTF_RenderText_Blended(police,"cheval", couleurNoire); 
    texte2 = TTF_RenderText_Blended(police,"chat", couleurNoire); 
    texte3 = TTF_RenderText_Blended(police,"chien", couleurNoire); 
    texte4 = TTF_RenderText_Blended(police,"poule", couleurNoire); 
    texte5 = TTF_RenderText_Blended(police,"tigre", couleurNoire); 

     SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); 
music1 = Mix_LoadWAV("cheval.ogg"); 
music2 = Mix_LoadWAV("chat.ogg"); 
music3 = Mix_LoadWAV("chien.ogg"); 
music4 = Mix_LoadWAV("Poule.wav"); 
music5 = Mix_LoadWAV("Tiger.wav"); 

    while (continuer) 
    { 
        SDL_WaitEvent(&event); 
        switch(event.type) 
        { 
            case SDL_QUIT: 
                continuer = 0; 
                break; 


 case SDL_MOUSEBUTTONUP: 
 switch (event.button.button) 
 { 
case SDL_BUTTON_LEFT: 
if((event.button.y>60 && event.button.y<160) && (event.button.x>700 && event.button.x <770)) 
{ 
 SDL_BlitSurface(fondcheval, NULL, ecran, &positionfondcheval); 
 SDL_BlitSurface(texte1, NULL, ecran, &position); 
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(chevalclic, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
 SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=1; 
  
 //SDL_Flip(ecran); 
 
 break; 
 } 
else if((event.button.y>160 && event.button.y<260) && (event.button.x>700 && event.button.x <770)) 
{ 
 SDL_BlitSurface(fondchat, NULL, ecran, &positionfondchat); 
 SDL_BlitSurface(texte2, NULL, ecran, &position); 
 SDL_BlitSurface(chatclic, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=2; 
 //SDL_Flip(ecran); 
 break; } 
else if((event.button.y>260 && event.button.y<360) && (event.button.x>700 && event.button.x <770)) 
 { 
 SDL_BlitSurface(fondchien, NULL, ecran, &positionfondchien); 
 SDL_BlitSurface(texte3, NULL, ecran, &position); 
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chienclic, NULL, ecran, &positionchien); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=3; 

 //SDL_Flip(ecran); 
} 
else if 
((event.button.y>360 && event.button.y<460) && (event.button.x>700 && event.button.x <770)) 
 { 
 SDL_BlitSurface(fondpoule, NULL, ecran, &positionfondpoule); 
 SDL_BlitSurface(texte4, NULL, ecran, &position);  
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(pouleclic, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=4; 

 //SDL_Flip(ecran); 

 } 
 else if 
((event.button.y>460 && event.button.y<560) && (event.button.x>700 && event.button.x <770)) 
{ 
 SDL_BlitSurface(fondtigre, NULL, ecran, &positionfondtigre); 
 SDL_BlitSurface(texte5, NULL, ecran, &position);  
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule);      
 SDL_BlitSurface(tigreclic, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=5; 

 //SDL_Flip(ecran); 
} 

else if((event.button.y>60 && event.button.y<160) && (event.button.x>600 && event.button.x <670)&&(d==1)) 
{   Mix_PlayChannel(1, music1, 0); 
//SDL_Flip(ecran);
} 
else if((event.button.y>60 && event.button.y<160) && (event.button.x>600 && event.button.x <670)&&(d==2)) 
{   Mix_PlayChannel(1, music2, 0); 
//SDL_Flip(ecran);
} 
else if((event.button.y>60 && event.button.y<160) && (event.button.x>600 && event.button.x <670)&&(d==3)) 
{   Mix_PlayChannel(1, music3, 0); 
//SDL_Flip(ecran);


} 
else if((event.button.y>60 && event.button.y<160) && (event.button.x>600 && event.button.x <670)&&(d==4)) 
{   Mix_PlayChannel(1, music4, 0); 
//SDL_Flip(ecran);
} 
else if((event.button.y>60 && event.button.y<160) && (event.button.x>600 && event.button.x <670)&&(d==5)) 
{   Mix_PlayChannel(1, music5, 0); 
//SDL_Flip(ecran);
} 

 break; 
} 


            case SDL_KEYDOWN: 
                switch(event.key.keysym.sym) 
                { 
                    case SDLK_UP: // Flèche haut 
b--; 

                      break; 
               
                    case SDLK_DOWN: // Flèche bas 
                   
 b++; 
} 
break; 


        } 
     

        SDL_Flip(ecran); 

if(b==1) 
{ 
 SDL_BlitSurface(fondcheval, NULL, ecran, &positionfondcheval); 
 SDL_BlitSurface(chevalclic, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(texte1, NULL, ecran, &position); 
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=1; 
} 
if(b==2) 
{ 
 SDL_BlitSurface(fondchat, NULL, ecran, &positionfondchat); 
 SDL_BlitSurface(chatclic, NULL, ecran, &positionchat); 
 SDL_BlitSurface(texte2, NULL, ecran, &position); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=2; 
} 
if(b==3) 
{ 
 SDL_BlitSurface(fondchien, NULL, ecran, &positionfondchien); 
 SDL_BlitSurface(chienclic, NULL, ecran, &positionchien); 
 SDL_BlitSurface(texte3, NULL, ecran, &position); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=3; 
} 
if(b==4) 
{ 
 SDL_BlitSurface(fondpoule, NULL, ecran, &positionfondpoule); 
 SDL_BlitSurface(pouleclic, NULL, ecran, &positionpoule); 
 SDL_BlitSurface(texte4, NULL, ecran, &position); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(tigre, NULL, ecran, &positiontigre); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=4; 
} 
if(b==5) 
{ 
 SDL_BlitSurface(fondtigre, NULL, ecran, &positionfondtigre); 
 SDL_BlitSurface(tigreclic, NULL, ecran, &positiontigre); 
 SDL_BlitSurface(texte5, NULL, ecran, &position); 
 SDL_BlitSurface(cheval, NULL, ecran, &positioncheval); 
 SDL_BlitSurface(chat, NULL, ecran, &positionchat); 
 SDL_BlitSurface(chien, NULL, ecran, &positionchien); 
 SDL_BlitSurface(poule, NULL, ecran, &positionpoule); 
SDL_BlitSurface(sound, NULL, ecran, &positionsound); 
d=5; 
} 
if(b>5) 
{b=0; 
}else if(b<0) 
{b=5;} 

    } 

SDL_FreeSurface(cheval); 
SDL_FreeSurface(chat); 
SDL_FreeSurface(chien); 
SDL_FreeSurface(poule); 
SDL_FreeSurface(tigre); 
SDL_FreeSurface(chevalclic); 
SDL_FreeSurface(chatclic); 
SDL_FreeSurface(chienclic); 
SDL_FreeSurface(poule); 
SDL_FreeSurface(tigreclic); 
SDL_FreeSurface(fondpoule); 
SDL_FreeSurface(fondchat); 
SDL_FreeSurface(fondcheval); 
SDL_FreeSurface(fondchien); 
SDL_FreeSurface(fondtigre); 
SDL_FreeSurface(texte1); 
SDL_FreeSurface(texte2); 
SDL_FreeSurface(texte3); 
SDL_FreeSurface(texte4); 
SDL_FreeSurface(texte5); 
Mix_FreeChunk(music1); 
Mix_FreeChunk(music2); 
Mix_FreeChunk(music3); 
Mix_FreeChunk(music4); 
Mix_FreeChunk(music5); 
   Mix_CloseAudio(); 
    SDL_Quit(); 

 TTF_CloseFont(police); 
    TTF_Quit(); 

    return EXIT_SUCCESS; 
}
